package com.example.nacosproviderpayment.controller;

import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaoren
 * @version 1.0
 * @description 热点限流
 * @date 2020/9/5 23:48
 **/
@RestController
@RequestMapping()
public class HotKetFlowLimitController {

    /**
     * 跟histrixcommand差不多
     * @param hotkey
     * @return
     */
    @GetMapping("query")
    @SentinelResource(value = "query",blockHandler = "handlerHotKeyException")
    public String query(String hotkey){
        return "hot key";
    }

    /**
     * 兜底的方法，一定要注意参数要和出错的controller参数一致（必须要有被限制的controller的方法）
     * @param hotkey
     * @param blockException
     * @return
     */
    public String handlerHotKeyException(String hotkey,BlockException blockException){
        return "热点规则限流";
    }
}
